package com.gsm.company.controller;

import com.gsm.common.entity.Result;
import com.gsm.common.entity.ResultCode;
import com.gsm.company.service.CompanyService;
import com.gsm.domain.company.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: java类作用描述
 * @Author: gaoshengmin
 * @CreateDate: 2020/2/7$ 11:46$
 * @UpdateUser: gaoshengmin
 * @UpdateDate: 2020/2/7$ 11:46$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @PostMapping
    public Result save(@RequestBody Company company){
        companyService.add(company);
        return new Result(ResultCode.SUCCESS);
    }

    @PutMapping("/{id}")
    public Result update(@PathVariable String id,@RequestBody Company company){
        company.setId(id);
        companyService.update(company);
        return new Result(ResultCode.SUCCESS);
    }


    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable String id){
        companyService.deleteById(id);
        return new Result(ResultCode.SUCCESS);
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable String id){
        Company company = companyService.findById(id);
        Result result = new Result(ResultCode.SUCCESS);
        result.setData(company);
        return result ;
    }

    @GetMapping
    public Result findBylist(){
        List<Company> all = companyService.findAll();
        Result result = new Result(ResultCode.SUCCESS);
        result.setData(all);
        return result ;
    }
}
